var fullscreen = {
	init:function(){
		// 全屏功能实现
		$(document).on('click', '.fullscreen-toggle', function() {
			fullscreen.fs()
		});
		// 监听全屏状态变化
		document.addEventListener('fullscreenchange', function() {
			console.log('change');
			if (!document.fullscreenElement) {
				//fullscreen.toggle()
			}
			fullscreen.toggle()
		});
		// 监听F11
		document.addEventListener('keydown', function(e) {
			if (e.key === 'F11' || e.keyCode === 122) {
				fullscreen.fs()
			}
		});
	},
	fs:function(){
		if (!document.fullscreenElement) {
			document.documentElement.requestFullscreen();
		} else {
			document.exitFullscreen().then(() => {});
		}
	},
	toggle:function(){
		if ($('.fullscreen-toggle').hasClass('fa-expand')) {
			$('.fullscreen-toggle').removeClass('fa-expand').addClass('fa-compress').attr('title', '退出全屏');
		} else {
			$('.fullscreen-toggle').removeClass('fa-compress').addClass('fa-expand').attr('title', '进入全屏');
		}
	}
}
function fullscreenEvent(){
	// 全屏
	$(document).on('click', '.fullscreen-toggle', function() {
		if (!document.fullscreenElement) {
			document.documentElement.requestFullscreen().then(() => {
				$('.fullscreen-toggle')
					.removeClass('fa-expand')
					.addClass('fa-compress')
					.attr('title', '退出全屏');
			});
		} else {
			document.exitFullscreen().then(() => {
				$('.fullscreen-toggle')
					.removeClass('fa-compress')
					.addClass('fa-expand')
					.attr('title', '进入全屏');
			});
		}
	});
	// 全屏状态变化
	document.addEventListener('fullscreenchange', function() {
		if (!document.fullscreenElement) {
			$('.fullscreen-toggle')
				.removeClass('fa-compress')
				.addClass('fa-expand')
				.attr('title', '进入全屏');
		}
	});
}

function navEvent(){

	$('.nav-collapsed').click(function(e) {
		e.stopPropagation();
		$('.nav-content').toggleClass('expanded');
		$(this).css('opacity', $('.nav-content').hasClass('expanded') ? '0' : '1');
	});

	$('#floating-nav').mouseleave(function() {
		$('.nav-content').removeClass('expanded');
		$('.nav-collapsed').css('opacity', '1');
	});

	$('.nav-content').click(function(e) {
		e.stopPropagation();
	});
	
	$('.nav-icon:not(.nav-icon-active)').click(function() {
		window.location.href = $(this).attr('data-url');
	});
}

$(function() {
	navEvent();
	//fullscreenEvent();
	fullscreen.init();

});